library(readr)
library(readxl)
library(gganimate)
## Loading required package: ggplot2
## No renderer backend detected. gganimate will default to writing frames to separate files
## Consider installing:
## - the `gifski` package for gif output
## - the `av` package for video output
## and restarting the R session
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Data <- read_xlsx("Data.xlsx")
Pembuatan grafik melibatkan beberapa tahapan, mulai dari persiapan data hingga presentasi grafik yang efektif. Berikut adalah tahapan dalam pembuatan grafik:
library(ggplot2)
library(readxl)
ggplot(Data, aes(x = Angka_Harapan_Hidup)) +
geom_histogram(binwidth = 5, fill = "skyblue", color = "black") +
labs(
title = "Distribusi Angka Harapan Hidup",
x = "Angka Harapan Hidup",
y = "Frekuensi"
) +
theme_minimal()
ggplot(Data,aes( x = Benua, y = Jumlah_anak, fill = Benua))+
geom_bar(stat = "identity",)+
labs (title="Jumlah Anak Per Benua",x= "Benua" ,y="Jumlah anak")
library(ggplot2)
ggplot(Data, aes(x = Tahun, y = Benua, fill = Angka_Harapan_Hidup)) +
geom_tile() +
scale_fill_gradient(low = "blue", high = "red") +
labs(
title = " ",
x = "Tahun",
y = "Benua",
fill = "Jumlah anak"
) +
theme_minimal()
# Muat library
library(ggplot2)
library(gganimate)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
library(plotly)
library(dplyr)
library(readxl)
# Baca data dari file Excel
data <- read_excel("Data.xlsx")
# Filter data (ambil top 10 negara per tahun berdasarkan Pendapatan_per_kapita)
data_filtered <- data %>%
group_by(Tahun) %>%
arrange(desc(Pendapatan_per_kapita)) %>%
slice_head(n = 10) %>%
ungroup()
# Buat grafik animasi menggunakan plotly
fig <- data_filtered %>%
plot_ly(
x = ~Pendapatan_per_kapita,
y = ~reorder(Negara, Pendapatan_per_kapita),
frame = ~Tahun,
color = ~Benua,
type = "bar",
orientation = "h"
) %>%
layout(
title = "Pendapatan per Kapita per Tahun",
xaxis = list(title = "Pendapatan per Kapita"),
yaxis = list(title = "Negara"),
barmode = "stack"
)
# Tampilkan grafik
fig
## Warning in p$x$data[firstFrame] <- p$x$frames[[1]]$data: number of items to
## replace is not a multiple of replacement length